package de.lgohlke.collection;

import de.lgohlke.format.UnitFormatter;

/**
 * <p>SavedSpace class.</p>
 *
 * @author lars
 * @version $Id: $
 */
public class SavedSpace
{
  private long rawSize   = 0;
  private long savedSize = 0;

  /** {@inheritDoc} */
  @Override
  public String toString()
  {
    return String.format("raw : %10s compressed : %10s (%4.2f%% of raw) -> saved %4.2f%% ", UnitFormatter.readableFileSize(rawSize),
        UnitFormatter.readableFileSize(savedSize), computePercentageSaved(), 100 - computePercentageSaved());
  }

  /**
   * <p>computePercentageSaved.</p>
   *
   * @return a double.
   */
  public double computePercentageSaved()
  {
    return savedSize == 0 ? 0D : savedSize / (double) rawSize * 100D;
  }

  /**
   * <p>Setter for the field <code>savedSize</code>.</p>
   *
   * @param absolute a long.
   */
  public void setSavedSize(final long absolute)
  {
    this.savedSize = absolute;
  }

  /**
   * <p>Getter for the field <code>savedSize</code>.</p>
   *
   * @return a long.
   */
  public long getSavedSize()
  {
    return savedSize;
  }

  /**
   * <p>add.</p>
   *
   * @param ss a {@link de.lgohlke.collection.SavedSpace} object.
   * @return a {@link de.lgohlke.collection.SavedSpace} object.
   */
  public SavedSpace add(final SavedSpace ss)
  {
    savedSize += ss.savedSize;
    rawSize += ss.rawSize;

    return this;
  }

  /**
   * <p>Setter for the field <code>rawSize</code>.</p>
   *
   * @param rawSize a long.
   */
  public void setRawSize(final long rawSize)
  {
    this.rawSize = rawSize;
  }

  /**
   * <p>Getter for the field <code>rawSize</code>.</p>
   *
   * @return a long.
   */
  public long getRawSize()
  {
    return rawSize;
  }
}
